package edu.gettysburg.catapp1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

/*
 * Contains two fields necessary in the class.
 * @menuOptions String[]: an array that gives the list of options when beginning
 * @firstActivity Intent: the placeholder for the Intent that is the next step in the app's cycle
 */
public class mainmenu extends Activity {

	final String[] menuOptions = new String[] 
	                                        	{"Choose A Tour", 
												"Download A Tour", 
												"Delete A Tour",
												"Exit"};
	
	private Intent firstActivity;
	public static final String PACKAGE_NAME = "edu.gettysburg.tour.viewer";

	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 * Begins user chosen activity based on selection from list
	 */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_layout);
		

		// R.layout.listview_layout is the custom layout
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.menulist, menuOptions);

		ListView listView = (ListView) findViewById(R.id.listView);
		listView.setAdapter(adapter);
		OnItemClickListener oicl = new OnItemClickListener(){

			/*
			 * (non-Javadoc)
			 * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
			 * Sets the main choices for tour beginning:
			 * case 0: Choose a Tour
			 * case 1: Download a Tour
			 * case 2: Delete a Tour
			 * case 3: Exit
			 */
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				switch (position){
				case 0:
					firstActivity = new Intent(getBaseContext(), choosetour.class);     
					startActivity(firstActivity);
					break;

				case 1:
					firstActivity = new Intent(getBaseContext(), downloadtour.class);     
					startActivity(firstActivity);
					break;

				case 2:
					firstActivity = new Intent(getBaseContext(), deletetour.class);     
					startActivity(firstActivity);
					break;

				case 3: 
					finish();
					System.exit(0);
					
				default:
					break;
				}
			}
		};
		listView.setOnItemClickListener(oicl);

	}

	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 * No additional menu options added.
	 */
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.intro_layout, menu);
		return true;
	}
}
